package com.easy.orm.demo;

import java.util.List;

import javax.sql.DataSource;

import com.easy.orm.jdbc.JdbcTemplate;
import com.easy.orm.source.EasyDataSource;

/**
 * 
 * JdbcTemplate
 * 
 * @author kun
 *
 */
public class JdbcTemplateDemo {

	/**
	 * 初始化数据源
	 * 
	 * @return 数据源
	 */
	public DataSource initDataSource() {
		EasyDataSource dataSource = new EasyDataSource();
		dataSource.setDriver("org.postgresql.Driver");
		dataSource.setUrl("jdbc:postgresql://192.168.2.119:5432/test");
		dataSource.setUsername("postgres");
		dataSource.setPassword("123456");
		return dataSource;
	}

	/**
	 * jdbcTemplate
	 */
	private JdbcTemplate jdbcTemplate;

	public JdbcTemplateDemo() {
		jdbcTemplate = new JdbcTemplate(initDataSource());
	}

	/**
	 * 查询
	 */
	public void query() {
		System.out.println(jdbcTemplate.queryForInt("select count(company_id) from company_profile "));
		List<Object[]> params = List.of(new Object[] { "341" }, new Object[] { "342" }, new Object[] { "343" },
				new Object[] { "344" }, new Object[] { "345" }, new Object[] { "346" }, new Object[] { "347" },
				new Object[] { "348" }, new Object[] { "349" }, new Object[] { "340" });
		jdbcTemplate.batch("insert into company_profile (company_id) values (?)", params);
		System.out.println(jdbcTemplate.queryForInt("select count(company_id) from company_profile "));
	}

	public static void main(String[] args) {
		JdbcTemplateDemo demo = new JdbcTemplateDemo();
		demo.query();
	}

}
